import {FlowerName} from "@/components/type";
import {Cluster, Pumpkin} from "@/modal/GardenCrop";
import type {Reactive} from "vue";

export class VegetableGarden {
  // 菜园全部菜畦总数
  public static totalPlots: number = 6;
  // 南瓜或者花卉总数
  public static totalOutCrops: number = 12;
  // 玉米或者豌豆总数
  public static totalInsideCrops: number = 24;
  // 菜畦园艺作物配置
  public static eachPlotConfig: Array<any> = [
    {
      plotIndex: 1,
      plotSq: [
        {type: "pumpkin", index: 0},
        {type: "crops", index: 0},
        {type: "flower", index: 0},
        {type: "crops", index: 1},
        {type: "pumpkin", index: 1},
        {type: "crops", index: 2},
        {type: "flower", index: 1},
        {type: "pumpkin", index: 2}
      ]
    }, {
      plotIndex: 2,
      plotSq: [
        {type: "flower", index: 2},
        {type: "pumpkin", index: 3},
        {type: "crops", index: 3},
        {type: "crops", index: 4},
        {type: "crops", index: 5},
        {type: "crops", index: 6},
        {type: "crops", index: 7}
      ]
    }, {
      plotIndex: 3,
      plotSq: [
        {type: "flower", index: 3},
        {type: "pumpkin", index: 4},
        {type: "flower", index: 4},
        {type: "crops", index: 8},
        {type: "crops", index: 9},
        {type: "pumpkin", index: 5},
        {type: "crops", index: 10},
        {type: "crops", index: 11},
        {type: "flower", index: 5}
      ]
    }, {
      plotIndex: 4,
      plotSq: [
        {type: "pumpkin", index: 6},
        {type: "crops", index: 12},
        {type: "flower", index: 6},
        {type: "crops", index: 13},
        {type: "pumpkin", index: 7},
        {type: "crops", index: 14},
        {type: "flower", index: 7},
        {type: "pumpkin", index: 8}
      ]
    }, {
      plotIndex: 5,
      plotSq: [
        {type: "flower", index: 8},
        {type: "crops", index: 15},
        {type: "crops", index: 16},
        {type: "crops", index: 17},
        {type: "pumpkin", index: 9},
        {type: "crops", index: 18},
        {type: "crops", index: 19}
      ]
    }, {
      plotIndex: 6,
      plotSq: [
        {type: "flower", index: 9},
        {type: "crops", index: 20},
        {type: "crops", index: 21},
        {type: "pumpkin", index: 10},
        {type: "crops", index: 22},
        {type: "crops", index: 23},
        {type: "flower", index: 10},
        {type: "pumpkin", index: 11},
        {type: "flower", index: 11}
      ]
    }
  ];
  // 菜畦玉米豌豆序列配置
  public static eachCornPeaSequence: Array<number> = [
    1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6
  ];
  // 外围南瓜序列配置
  public static pumpkinSequence: Array<any> = [
    {
      ripeStage: 4,
      goodsNum: 3,
      plotIndex: 1
    }, {
      ripeStage: 3,
      goodsNum: 2,
      plotIndex: 1
    }, {
      ripeStage: 1,
      goodsNum: 1,
      plotIndex: 1
    }, {
      ripeStage: 4,
      goodsNum: 3,
      plotIndex: 2
    }, {
      ripeStage: 2,
      goodsNum: 1,
      plotIndex: 3
    }, {
      ripeStage: 3,
      goodsNum: 2,
      plotIndex: 3
    }, {
      ripeStage: 4,
      goodsNum: 3,
      plotIndex: 4
    }, {
      ripeStage: 3,
      goodsNum: 3,
      plotIndex: 4
    }, {
      ripeStage: 1,
      goodsNum: 1,
      plotIndex: 4
    }, {
      ripeStage: 2,
      goodsNum: 1,
      plotIndex: 5
    }, {
      ripeStage: 4,
      goodsNum: 3,
      plotIndex: 6
    }, {
      ripeStage: 3,
      goodsNum: 2,
      plotIndex: 6
    }
  ];
  // 外围花卉行动配置
  public static clusterSequence: Array<any> = [
    {
      name: FlowerName.HYACINTH,
      chineseName: FlowerName.CHINESE_HYACINTH,
      direction: "left",
      plotIndex: 1
    }, {
      name: FlowerName.HYDRANGEA,
      chineseName: FlowerName.CHINESE_HYDRANGEA,
      direction: "left",
      plotIndex: 1
    }, {
      name: FlowerName.IRIS,
      chineseName: FlowerName.CHINESE_IRIS,
      direction: "top",
      plotIndex: 2
    }, {
      name: FlowerName.SAFFRON,
      chineseName: FlowerName.CHINESE_SAFFRON,
      direction: "top",
      plotIndex: 3
    }, {
      name: FlowerName.TULIP,
      chineseName: FlowerName.CHINESE_TULIP,
      direction: "right",
      plotIndex: 3
    }, {
      name: FlowerName.IRIS,
      chineseName: FlowerName.CHINESE_IRIS,
      direction: "right",
      plotIndex: 3
    }, {
      name: FlowerName.DAFFODIL,
      chineseName: FlowerName.CHINESE_DAFFODIL,
      direction: "right",
      plotIndex: 4
    }, {
      name: FlowerName.HYACINTH,
      chineseName: FlowerName.CHINESE_HYACINTH,
      direction: "bottom",
      plotIndex: 4
    }, {
      name: FlowerName.HYDRANGEA,
      chineseName: FlowerName.CHINESE_HYDRANGEA,
      direction: "bottom",
      plotIndex: 5
    }, {
      name: FlowerName.SAFFRON,
      chineseName: FlowerName.CHINESE_SAFFRON,
      direction: "bottom",
      plotIndex: 6
    }, {
      name: FlowerName.TULIP,
      chineseName: FlowerName.CHINESE_TULIP,
      direction: "left",
      plotIndex: 6
    }, {
      name: FlowerName.DAFFODIL,
      chineseName: FlowerName.CHINESE_DAFFODIL,
      direction: "left",
      plotIndex: 6
    }
  ];
  // 查询夹在成熟南瓜中间的所有花丛
  public static getClustersSurroundByPumpkin = (modal: Reactive<Pumpkin>,
                                                arr1: Reactive<Pumpkin[]>,
                                                arr2: Reactive<Cluster[]>) => {
    const currentIndex = arr1.indexOf(modal);
    const nextIndex = currentIndex === arr1.length - 1 ? 0 : currentIndex + 1;
    const prevIndex = currentIndex === 0 ? arr1.length - 1 : currentIndex - 1;
    let pendingCluster: Reactive<Cluster[]> = [];
    if (arr1[nextIndex].isRipen) pendingCluster.push(arr2[currentIndex]);
    if (arr1[prevIndex].isRipen) pendingCluster.push(arr2[prevIndex]);
    return pendingCluster;
  };
}